package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JDBCDemo8 {
    public static void main(String[] args) {
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(), "注册", "注册");

        System.out.println(userInfo);

        try (
                Connection conn = DBUtil.getConnection();
        ) {
            String str ="INSERT INTO userinfo " +
                    "(username,password,nickname,age) " +
                    "VALUES(?,?,?,?)";
            PreparedStatement ps =  conn.prepareStatement(str);
            ps.setString(1,userInfo.getUsername());
            ps.setString(2,userInfo.getPassword());
            ps.setString(3,userInfo.getNickname());
            ps.setInt(4,userInfo.getAge());

            int num =  ps.executeUpdate();
            if(num>0){
                System.out.println("注册成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
